package com.yanqu.road.server.cmd.activity.stronghold.wild;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.stronghold.StrongholdWarUserData;
import com.yanqu.road.pb.activity.StrongholdWarProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.strongholdwar.StrongholdModule;
import com.yanqu.road.server.manger.activity.strongholdwar.StrongholdActivityMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.*;

@Cmd(code = GameProtocol.S_STRONGHOLD_WAR_WILD_SEARCH, desc = "野外据点搜索")
public class StrongholdWildSearchCmd extends AbstractCommand {
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        //是否已派遣人才
        //是否有体力，先扣体力，根据跨服返回结果，如果不允许搜索，加回已扣体力
        //发到跨服检测
        ActivityInfo activityInfo = StrongholdActivityMgr.getActivityInfo();
        StrongholdWarUserData warData = player.getModule(StrongholdModule.class).getStrongholdWarData(activityInfo.getActivityId());
        player.getModule(StrongholdModule.class).calcPower(warData);
        if (warData.getPower() < StrongholdActivityMgr.getSearchPower()) {
            ret = GameErrorCode.E_STRONGHOLD_POWER_NOT_ENOUHT;
            sendPlayer(player);
            return;
        }
        if (!StrongholdActivityMgr.isWildTime()) {
            ret = GameErrorCode.E_STRONGHOLD_POWER_NOT_ENOUHT;
            sendPlayer(player);
            return;
        }
        StrongholdWarProto.CrossStrongholdSearchReqMsg.Builder msg = StrongholdWarProto.CrossStrongholdSearchReqMsg.newBuilder();
        msg.setActivityId(activityInfo.getActivityId());
        player.sendUnionActivityGroupPacket(Protocol.C_CROSS_STRONGHOLD_WILD_SEARCH, msg, msg.getActivityId());
    }

    private void sendPlayer(GamePlayer player) {
        StrongholdWarProto.StrongholdSearchRespMsg.Builder resp = StrongholdWarProto.StrongholdSearchRespMsg.newBuilder();
        resp.setRet(ret);
        player.sendPacket(ClientProtocol.U_STRONGHOLD_WAR_WILD_SEARCH, resp);
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
